--你须愧悔
local nixukuihui = fk.CreateSkill {
    name = "mcdh_nixukuihui",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

nixukuihui:addEffect('active',{
    target_num = 1 ,
    target_filter = function(self,player, to_select, selected, selected_cards)
        local room = Fk:currentRoom()
        local to = to_select
        local tar = table.filter(room.alive_players,function(p) return p:distanceTo(player) > to:distanceTo(player) end)
        return #tar == 0 and #selected == 0
    end,
    card_filter = Util.FalseFunc,
    can_use = function(self, player, card, extra_data)
        return player:getMark("mcdh_charge") >= 3
    end,
    on_use = function(self, room, effect)
        local player = effect.from
        local target = effect.tos[1]
        lib.LoseCharge(player,player,3 ,self.name)
        player:drawCards(math.min(player:distanceTo(target), 5),self.name)
        if player:isAlive() then
            local num = #player:getCardIds(Player.Hand) - math.min(player:distanceTo(target), 5)
            if num > 0 then
                room:askForDiscard(player, num, num, false, self.name, false, ".", "#mcdh_nixukuihui_askdiscard:::"..num)
            end
        end
        if player:isAlive() and target:isAlive() and player:canUseTo(Fk:cloneCard("fire_attack"),target) then
            room:useVirtualCard("fire_attack", nil, player, target, self.name)
        end
    end
})

Fk:loadTranslationTable{
    ["mcdh_nixukuihui"] = "须愧",
    [":mcdh_nixukuihui"] = "『你须愧悔』<br>蓄力技(3)，出牌阶段限一次，你可以选择一名与你距离最远的角色，然后摸X张牌并将手牌弃置至X张，视为对其使用一张【火攻】（X为你计算与其之间的距离，且至多为5）",
    ["#mcdh_nixukuihui_askdiscard"] = "你须愧悔：选择%arg张手牌弃置",
}

return nixukuihui